


class WalkCommand extends command.Command {

    private x: number;
    private y: number;

    constructor(x: number, y: number) {
        super();
        this.x = x;
        this.y = y;
    }

    execute(notifyFinish: Function) {

        console.log(`开始走路！！！从${this.x}出发`);
        const map = mapManager.getMap();
        map.grid.setEndNode(this.x, this.y);
        const findpath = new astar.AStar();
        findpath.setHeurisitic(findpath.diagonal)
        findpath.findPath(map.grid);
        const path = findpath._path;

        if (path) {
            path.shift();
            //user.goto(path);

            const func = () => {
                //user.removeEventListener("goOver", func);
                notifyFinish();
            }
            //user.addEventListener("goOver", func)
        }
    }
}

class PickCommand extends command.Command {


    private weapon: Item;
    constructor(weapon: Item) {
        super();
        this.weapon = weapon;
    }

    execute(notifyFinish: Function) {
        //user.pick(this.weapon)
        //user.level++;
        const map = mapManager.getMap();
        map.removeItem(this.weapon);
        notifyFinish();
    }
}

class GotoNextMapCommand extends command.Command {

    constructor(private mapId: string) {
        super();
    }

    execute() {

        console.log('换地图！！')
        mapManager.changeMap(this.mapId)
    }
}

class TalkCommand extends command.Command {

    private npc: Npc;
    constructor(npc: Npc) {
        super();
        this.npc = npc;
    }


    execute(notifyFinish: Function) {

        console.log(`开始对话:${this.npc.toString()}`)
        let mission: Mission | null = null;
        if (this.npc.canSubmitMissions.length > 0) {
            mission = this.npc.canSubmitMissions[0];
        }
        if (this.npc.canAcceptMissions.length > 0) {
            mission = this.npc.canAcceptMissions[0];
        }
        else {

        }
        if (mission) {
            const dialog = new TalkDialog();
            dialogContainer.addChild(dialog);
            dialog.setMission(mission);
            dialog.addEventListener('close', () => {
                dialogContainer.removeChild(dialog)
                if (mission) {
                    if (mission.status == MissionStatus.CAN_SUBMIT) {
                        console.log('提交任务', mission.title)
                        missionManager.submitMission(mission);
                    }
                    else if (mission.status == MissionStatus.CAN_ACCEPT) {
                        console.log('接受任务', mission.title)
                        missionManager.acceptMission(mission);
                    }
                }
                notifyFinish();

            })
        }
        else {
            notifyFinish();
        }






    }
}
